package com.tscnd.core.service.log.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.test.annotation.Rollback;

import com.tscnd.core.Constants;
import com.tscnd.core.dao.log.IOptionLogDao;
import com.tscnd.core.entity.BasePage;
import com.tscnd.core.entity.log.OptionLog;
import com.tscnd.core.exception.TSException;
import com.tscnd.core.service.log.IOptionLogService;

@Service("optionLogService")
public class OptionLogServiceImpl implements IOptionLogService {

	@Autowired
	private IOptionLogDao optionLogDao;

	@Override
	@Rollback(value = true)
	public void save(OptionLog optionLog) throws TSException
	{
		try
		{
			int fg = optionLogDao.save(optionLog);
			if (fg <= Constants.FIGURE_ZERO)
			{
				throw new RuntimeException("运行异常....");
			}
		} catch (Exception e)
		{
			e.printStackTrace();
			throw new TSException("添加日志信息失败\r\n" + e.getMessage());
		}
	}

	@Override
	public Map<String,Object> findPage(Map<String,Object> map)throws TSException
	{
		try
		{
			BasePage page=(BasePage) map.get("page");
			map.put("startNo", page.getStartNo());
			map.put("rows",page.getRows());
			map.put("sord",page.getSord());
			page.setTotalCount(optionLogDao.count(map));
			map.put("list", optionLogDao.getPage(map));
			map.put("page", page);
			return map;
		} catch (Exception e)
		{
			e.printStackTrace();
			throw new TSException("查询日志信息失败\r\n" + e.getMessage());
		}
	}
	
}
